package cn.itcast.bos.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.domain.base.Courier;
import cn.itcast.bos.repository.CourierRepository;
import cn.itcast.bos.service.CourierService;

@Service
@Transactional
public class CourierServiceImpl implements CourierService {
	
	@Autowired
	private CourierRepository courierSRepository;
	
	///保存
	@Override
	public void save(Courier courier) {
		courierSRepository.save(courier);
	}
	
	//无条件的分页查询
	@Override
	public Page<Courier> findPageQuery(Pageable pageable) {
		return courierSRepository.findAll(pageable);
	}
	
	//有条件的分页查询
	@Override
	public Page<Courier> findPageQueryCondition(Specification<Courier> spec,Pageable pageable) {
		return courierSRepository.findAll(spec, pageable);
	}

	@Override
	public void deleteCourier(String[] arrId) {
		if(arrId!=null&&arrId.length>0){
			for (String idStr : arrId) {
				courierSRepository.updateDeltag(Integer.parseInt(idStr));
			}
		}
		
	}
	//还原
	@Override
	public void huanyuanCourier(String[] arrId) {
		if(arrId!=null&&arrId.length>0){
			for (String idStr : arrId) {
				courierSRepository.huanyuanDeltag(Integer.parseInt(idStr));
			}
		}
	}
}
